package com.example.JcGQS.dao;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.JcGQS.mapper.AuditRelationshipMapper;
import com.example.JcGQS.pojo.entity.AuditRelationship;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * auditRelationshipDao
 * @author 末日
 * @date 2023/11/21
 */
@Component
public class AuditRelationshipDao {
    @Autowired
    AuditRelationshipMapper auditRelationshipMapper;

    /**
     * 根据采购id,审核人id修改审核状态
     * @param auditRelationship
     */
    public void auditRelationshipUpdate(AuditRelationship auditRelationship,Integer userId){

        UpdateWrapper<AuditRelationship> updateWrapper = new UpdateWrapper();
        updateWrapper.eq("purchase_id",auditRelationship.getPurchaseId());
        updateWrapper.eq("audit_relationship_user_id",userId);
        auditRelationshipMapper.update(auditRelationship,updateWrapper);
    }
/**
 * 新增审核关系数据
 */
public void auditRelationshipInsert(AuditRelationship auditRelationship){
    auditRelationshipMapper.insert(auditRelationship);
}


/**
 * 删除审核关系数据
 */
public void auditRelationshipDelete(Integer purchaseId){
    QueryWrapper<AuditRelationship> wrapper = new QueryWrapper<>();
    wrapper.eq("purchase_id",purchaseId);
    auditRelationshipMapper.delete(wrapper);
}
    /**
     * 根据采购信息id查询审核关系列表
     * @param id
     * @return
     */
    public List<AuditRelationship> auditRelationshipSelectId(Integer id){
        QueryWrapper<AuditRelationship> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("purchase_id",id);
        queryWrapper.orderByAsc("audit_relationship_id");
        return auditRelationshipMapper.selectList(queryWrapper);
    }
}
